package db

import "strings"

type QueryResult struct {
	SQL    string      `json:"sql"`
	Result interface{} `json:"result"`
}

// DatabaseInterface defines the common interface for different database types
type DatabaseInterface interface {
	Close() error
	ExecuteQuery(query string) (interface{}, error)
	GetTables(includePatterns, excludePatterns []string) ([]string, error)
	GetTableDDL(tableName string) (string, error)
	ProcessSQLFile(sqlPath string) error
	InitializeTableFiles(workDir string, includeTablePatterns, excludeTablePatterns []string) error
	IsReadOnlyQuery(query string) bool
	GenerateDDLChange(ddlPath string) error
	// 新增：处理JSON文件修改，生成UPDATE语句
	ProcessJSONModification(jsonPath string) error
	// 新增：处理insert.sql文件，将JSON转换为INSERT语句
	ProcessInsertSQL(insertPath string) error
}

// IsReadOnlyQuery checks if a query is read-only (SELECT, SHOW, DESCRIBE, EXPLAIN)
func IsReadOnlyQuery(query string) bool {
	query = strings.TrimSpace(strings.ToUpper(query))
	readOnlyPrefixes := []string{"SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "WITH"}

	for _, prefix := range readOnlyPrefixes {
		if strings.HasPrefix(query, prefix) {
			return true
		}
	}
	return false
}
